﻿//--------------------------------------------------------------------
// All Rights Reserved , Copyright (C) 2012 ,  TECH, Ltd. 
//--------------------------------------------------------------------

using System;
using System.Data;
using System.Reflection;
using System.ServiceModel;

namespace RDIFramework.ServiceAdapter
{
    using RDIFramework.BusinessEntity;
    using RDIFramework.IService;
	using RDIFramework.Utilities;
	

	/// <summary>
    /// ModuleService
	/// 服务层
	/// 
	/// 修改记录
	/// 
	///		2012-03-02 版本：1.0 EricHu 建立。
	///		
	/// 版本：1.0
	///
	/// <author>
	///		<name>EricHu</name>
	///		<date>2012-03-02</date>
	/// </author> 
	/// </summary>
	[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
	public class ModuleService : System.MarshalByRefObject, IModuleService
	{
        private readonly string serviceName = RDIFrameworkMessage.ModuleService;

        /// <summary>
        /// .NET快速开发整合框架（RDIFramework.NET）数据库连接
        /// </summary>
        private readonly string RDIFrameworkDbConection = SystemInfo.RDIFrameworkDbConection;

        #region public DataTable GetDT(UserInfo userInfo):获取模块列表
        /// <summary>
        /// 获取模块列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <returns>数据表</returns>
        public DataTable GetDT(UserInfo userInfo)
        {
            DataTable dataTable = new DataTable(PiModuleTable.TableName);
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                    dataTable = moduleManager.GetDT(PiModuleTable.FieldDeleteMark, 0, PiModuleTable.FieldSortCode);
                    dataTable.DefaultView.Sort = PiModuleTable.FieldSortCode;
                    dataTable.TableName = PiModuleTable.TableName;
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_GetDT, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }
            return dataTable;
        }
        #endregion

        #region public DataTable GetDTByIds(UserInfo userInfo, string[] ids):按主键数组获取列表
        /// <summary>
        /// 按主键数组获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">角色主键</param>
        /// <returns>数据表</returns>
        public DataTable GetDTByIds(UserInfo userInfo, string[] ids)
        {
            DataTable dataTable = new DataTable(PiRoleTable.TableName);
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                    dataTable = moduleManager.GetDT(PiModuleTable.FieldId, ids, PiModuleTable.FieldSortCode);
                    dataTable.TableName = PiModuleTable.TableName;
                    LogManager.Instance.Add(dbProvider, userInfo, serviceName, RDIFrameworkMessage.RoleService_GetDTByIds, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }
            return dataTable;
        }
        #endregion

        #region public PiModuleEntity GetEntity(UserInfo userInfo, string id):获取实体
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public PiModuleEntity GetEntity(UserInfo userInfo, string id)
        {
            PiModuleEntity moduleEntity = null;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                    moduleEntity = moduleManager.GetEntity(id);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_GetEntity, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }
            return moduleEntity;
        }
        #endregion

        #region public string GetFullNameByCode(UserInfo userInfo, string code):通过编号获取模块名称
        /// <summary>
        /// 通过编号获取模块名称
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="code">编号</param>
        /// <returns>数据表</returns>
        public string GetFullNameByCode(UserInfo userInfo, string code)
        {
            string returnValue = string.Empty;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    // 调用 BU Get 方法
                    PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                    returnValue = moduleManager.GetFullNameByCode(code);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_GetFullNameByCode, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }
            return returnValue;
        }
        #endregion

        #region public string Add(UserInfo userInfo, PiModuleEntity moduleEntity, out string statusCode, out string statusMessage):添加模块菜单
        /// <summary>
        /// 添加模块菜单
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="moduleEntity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状消息</param>
        /// <returns>主键</returns>
        public string Add(UserInfo userInfo, PiModuleEntity moduleEntity, out string statusCode, out string statusMessage)
        {          
            statusCode = string.Empty;
            statusMessage = string.Empty;

            string returnValue = string.Empty;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                    // 调用方法，并且返回运行结果
                    returnValue = moduleManager.Add(moduleEntity, out statusCode);
                    // 获得状态消息
                    statusMessage = moduleManager.GetStateMessage(statusCode);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_Add, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }
            return returnValue;
        }
        #endregion

        #region public int Update(UserInfo userInfo, PiModuleEntity moduleEntity, out string statusCode, out string statusMessage):更新模块菜单
        /// <summary>
        /// 更新模块菜单
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="moduleEntity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状消息</param>
        /// <returns>影响行数</returns>
        public int Update(UserInfo userInfo, PiModuleEntity moduleEntity, out string statusCode, out string statusMessage)
        {
            statusCode = string.Empty;
            statusMessage = string.Empty;
            int returnValue = 0;

            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                    // 调用方法，并且返回运行结果
                    returnValue = moduleManager.Update(moduleEntity, out statusCode);
                    // 获得状态消息
                    statusMessage = moduleManager.GetStateMessage(statusCode);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_Update, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }
            return returnValue;
        }
        #endregion

        #region public DataTable GetDTByParent(UserInfo userInfo, string parentId):按父节点获得列表
        /// <summary>
        /// 按父节点获得列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="parentId">父结点主键</param>
        /// <returns>数据表</returns>
        public DataTable GetDTByParent(UserInfo userInfo, string parentId)
        {
            DataTable dataTable = new DataTable(PiModuleTable.TableName);
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                    dataTable = moduleManager.GetDT(PiModuleTable.FieldDeleteMark, 0, PiModuleTable.FieldParentId, parentId);
                    dataTable.DefaultView.Sort = PiModuleTable.FieldSortCode;
                    dataTable.TableName = PiModuleTable.TableName;
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_GetDTByParent, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }
            return dataTable;
        }
        #endregion

        #region public int Delete(UserInfo userInfo, string id):删除模块
        /// <summary>
        /// 删除模块
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <param name="parentId">父结点主键</param>
        /// <returns>影响行数</returns>
        public int Delete(UserInfo userInfo, string id)
        {
            int returnValue = 0;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                    returnValue = moduleManager.Delete(id);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_Delete, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }
            return returnValue;
        }
        #endregion

        #region public int BatchDelete(UserInfo userInfo, string[] ids):批量删除模块
        /// <summary>
        /// 批量删除模块
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <param name="parentId">父结点主键</param>
        /// <returns>数据表</returns>
        public int BatchDelete(UserInfo userInfo, string[] ids)
        {
            int returnValue = 0;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                    returnValue = moduleManager.Delete(ids);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_BatchDelete, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }
            return returnValue;
        }
        #endregion

        #region public int SetDeleted(UserInfo userInfo, string[] ids) 批量打删除标志
        /// <summary>
        /// 批量打删除标志
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <returns>影响行数</returns>
        public int SetDeleted(UserInfo userInfo, string[] ids)
        {
            int returnValue = 0;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                    returnValue = moduleManager.SetDeleted(ids);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_SetDeleted, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }
            return returnValue;
        }
        #endregion

        #region public int MoveTo(UserInfo userInfo, string moduleId, string parentId):移动模块菜单
        /// <summary>
        /// 移动模块菜单
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="organizeId">组织机构主键</param>
        /// <param name="parentId">父结点主键</param>
        /// <returns>数据表</returns>
        public int MoveTo(UserInfo userInfo, string moduleId, string parentId)
        {
            int returnValue = 0;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                    returnValue = moduleManager.SetProperty(moduleId, PiModuleTable.FieldParentId, parentId);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_MoveTo, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }
            return returnValue;
        }
        #endregion

        #region public int BatchMoveTo(UserInfo userInfo, string[] moduleIds, string parentId):批量移动数据
        /// <summary>
        /// 批量移动数据
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="organizeIds">组织机构主键数组</param>
        /// <param name="parentId">父结点主键</param>
        /// <returns>数据表</returns>
        public int BatchMoveTo(UserInfo userInfo, string[] moduleIds, string parentId)
        {
            int returnValue = 0;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                    for (int i = 0; i < moduleIds.Length; i++)
                    {
                        returnValue += moduleManager.SetProperty(moduleIds[i], PiModuleTable.FieldParentId, parentId);
                    }
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_BatchMoveTo, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }

            return returnValue;
        }
        #endregion

        #region public int BatchSave(UserInfo userInfo, DataTable dataTable):
        /// <summary>
        /// 批量保存
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="dataTable">数据表</param>
        /// <param name="parentId">父结点主键</param>
        /// <returns>影响行数</returns>
        public int BatchSave(UserInfo userInfo, DataTable dataTable)
        {
            int returnValue = 0;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                    returnValue = moduleManager.BatchSave(dataTable);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_BatchSave, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }

            return returnValue;
        }
        #endregion

        #region public int SetSortCode(UserInfo userInfo, string[] ids):保存排序顺序
        /// <summary>
        /// 保存排序顺序
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <returns>影响行数</returns>
        public int SetSortCode(UserInfo userInfo, string[] ids)
        {
            int returnValue = 0;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    if (userInfo.IsAdministrator)
                    {
                        PiModuleManager moduleManager = new PiModuleManager(dbProvider, userInfo);
                        returnValue = moduleManager.BatchSetSortCode(ids);
                    }
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_SetSortCode, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }

            return returnValue;
        }
        #endregion

        #region public DataTable GetPermissionDT(UserInfo userInfo, string moduleId) 获取关联的权限项列表
        /// <summary>
        /// 获取关联的权限项列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="moduleId">主键</param>
        /// <returns>数据表</returns>
        public DataTable GetPermissionDT(UserInfo userInfo, string moduleId)
        {
            DataTable dataTable = new DataTable(PiPermissionTable.TableName);
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PermissionModuleManager modulePermissionManager = new PermissionModuleManager(dbProvider, userInfo);
                    string[] ids = modulePermissionManager.GetPermissionIds(moduleId);
                    PiPermissionItemManager permissionAdminManager = new PiPermissionItemManager(dbProvider, userInfo);
                    dataTable = permissionAdminManager.GetDT(ids);
                    dataTable.TableName = PiPermissionItemTable.TableName;
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_GetPermissionDT, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }

            return dataTable;
        }
        #endregion

        #region public string[] GetIdsByPermission(UserInfo userInfo, string permissionItemId):菜单主健数组
        /// <summary>
        /// 菜单主健数组
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="permissionItemId">操作权限主键</param>
        /// <returns>主键数组</returns>
        public string[] GetIdsByPermission(UserInfo userInfo, string permissionItemId)
        {
            string[] returnValue = null;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PermissionModuleManager modulePermissionManager = new PermissionModuleManager(dbProvider, userInfo);
                    returnValue = modulePermissionManager.GetModuleIds(permissionItemId);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_GetIdsByPermission, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }

            return returnValue;
        }
        #endregion

        #region public string BatchAddPermissions(UserInfo userInfo, string moduleId, string[] permissionItemIds) 模块批量关联操作权限项
        /// <summary>
        /// 模块批量关联操作权限项
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="moduleId">模块主键</param>
        /// <param name="permissionItemIds">权限主键</param>
        /// <returns>影响行数</returns>
        public int BatchAddPermissions(UserInfo userInfo, string moduleId, string[] permissionItemIds)
        {
            int returnValue = 0;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PermissionModuleManager modulePermissionManager = new PermissionModuleManager(dbProvider, userInfo);
                    returnValue = modulePermissionManager.Add(moduleId, permissionItemIds);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_BatchAddPermissions, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }

            return returnValue;
        }
        #endregion

        #region public int BatchAddModules(UserInfo userInfo, string permissionItemId, string[] moduleIds):操作权限项关联模块菜单
        /// <summary>
        /// 操作权限项关联模块菜单
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="permissionItemId">权限主键</param>
        /// <param name="moduleIds">模块主键</param>
        /// <returns>影响行数</returns>
        public int BatchAddModules(UserInfo userInfo, string permissionItemId, string[] moduleIds)
        {    
            int returnValue = 0;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PermissionModuleManager modulePermissionManager = new PermissionModuleManager(dbProvider, userInfo);
                    returnValue = modulePermissionManager.Add(moduleIds, permissionItemId);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_BatchAddModules, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }

            return returnValue;
        }
        #endregion

        #region public string BatchDeletePermissions(UserInfo userInfo, string moduleId, string[] permissionItemIds) 撤销模块菜单与操作权限项的关联
        /// <summary>
        /// 撤销模块菜单与操作权限项的关联
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="moduleId">模块主键</param>
        /// <param name="permissionItemIds">权限主键</param>
        /// <returns>影响行数</returns>
        public int BatchDeletePermissions(UserInfo userInfo, string moduleId, string[] permissionItemIds)
        {
            int returnValue = 0;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PermissionModuleManager modulePermissionManager = new PermissionModuleManager(dbProvider, userInfo);
                    returnValue = modulePermissionManager.Delete(moduleId, permissionItemIds);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_BatchDletePermissions, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }

            return returnValue;
        }
        #endregion

        #region public int BatchDeleteModules(UserInfo userInfo, string permissionItemId, string[] modulesIds):撤销操作权限项与模块菜单的关联
        /// <summary>
        /// 撤销操作权限项与模块菜单的关联
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="permissionItemId">权限主键</param>
        /// <param name="modulesIds">模块主键</param>
        /// <returns>影响行数</returns>
        public int BatchDeleteModules(UserInfo userInfo, string permissionItemId, string[] modulesIds)
        {
            int returnValue = 0;
            using (IDbProvider dbProvider = DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType))
            {
                try
                {
                    dbProvider.Open(RDIFrameworkDbConection);
                    PermissionModuleManager modulePermissionManager = new PermissionModuleManager(dbProvider, userInfo);
                    returnValue = modulePermissionManager.Delete(modulesIds, permissionItemId);
                    LogManager.Instance.Add(dbProvider, userInfo, this.serviceName, RDIFrameworkMessage.ModuleService_BatchDleteModules, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    CiExceptionManager.LogException(dbProvider, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbProvider.Close();
                }
            }
            return returnValue;
        }
        #endregion
    }
}
